﻿using System;
using System.Data;
using System.Collections.Generic;

using Catering_Model;
namespace Catering_Rules
{
    /// <summary>
    /// ContractorInfo
    /// </summary>
    public partial class ContractorInfo
    {
        private readonly Catering_Operation.ContractorInfo dal = new Catering_Operation.ContractorInfo();
        public ContractorInfo()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Catering_Model.ContractorInfo model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.ContractorInfo model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContractorInfo GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Catering_Model.ContractorInfo GetModelByCache(int id)
        {

            string CacheKey = "ContractorInfoModel-" + id;
            object objModel = Catering_DBOpertion.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = Catering_DBOpertion.ConfigHelper.GetConfigInt("ModelCache");
                        Catering_DBOpertion.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Catering_Model.ContractorInfo)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.ContractorInfo> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.ContractorInfo> DataTableToList(DataTable dt)
        {
            List<Catering_Model.ContractorInfo> modelList = new List<Catering_Model.ContractorInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.ContractorInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Catering_Model.ContractorInfo();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["CID"] != null && dt.Rows[n]["CID"].ToString() != "")
                    {
                        model.CID = int.Parse(dt.Rows[n]["CID"].ToString());
                    }
                    if (dt.Rows[n]["CName"] != null && dt.Rows[n]["CName"].ToString() != "")
                    {
                        model.CName = dt.Rows[n]["CName"].ToString();
                    }
                    if (dt.Rows[n]["GroupID"] != null && dt.Rows[n]["GroupID"].ToString() != "")
                    {
                        model.GroupID = dt.Rows[n]["GroupID"].ToString();
                    }
                    if (dt.Rows[n]["ClassID"] != null && dt.Rows[n]["ClassID"].ToString() != "")
                    {
                        model.ClassID = dt.Rows[n]["ClassID"].ToString();
                    }
                    if (dt.Rows[n]["CardNo"] != null && dt.Rows[n]["CardNo"].ToString() != "")
                    {
                        model.CardNo = dt.Rows[n]["CardNo"].ToString();
                    }
                    if (dt.Rows[n]["JobCard"] != null && dt.Rows[n]["JobCard"].ToString() != "")
                    {
                        model.JobCard = dt.Rows[n]["JobCard"].ToString();
                    }
                    if (dt.Rows[n]["Effective"] != null && dt.Rows[n]["Effective"].ToString() != "")
                    {
                        model.Effective = dt.Rows[n]["Effective"].ToString();
                    }
                    if (dt.Rows[n]["Tel"] != null && dt.Rows[n]["Tel"].ToString() != "")
                    {
                        model.Tel = dt.Rows[n]["Tel"].ToString();
                    }
                    if (dt.Rows[n]["ConDesc"] != null && dt.Rows[n]["ConDesc"].ToString() != "")
                    {
                        model.ConDesc = dt.Rows[n]["ConDesc"].ToString();
                    }
                    if (dt.Rows[n]["OldClassID"] != null && dt.Rows[n]["OldClassID"].ToString() != "")
                    {
                        model.OldClassID = dt.Rows[n]["OldClassID"].ToString();
                    }
                    if (dt.Rows[n]["OldGroupID"] != null && dt.Rows[n]["OldGroupID"].ToString() != "")
                    {
                        model.OldGroupID = dt.Rows[n]["OldGroupID"].ToString();
                    }
                    if (dt.Rows[n]["ChangeClassDate"] != null && dt.Rows[n]["ChangeClassDate"].ToString() != "")
                    {
                        model.ChangeClassDate = Convert.ToDateTime(dt.Rows[n]["EffectiveEnd"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        /// <summary>
        /// 根据条件获取数据总条数
        /// </summary>
        public int GetCountBywhere(string where)
        {
            return dal.GetCountBywhere(where);
        }

        #endregion  Method
    }
}

